const request = {
    post: function (data, url, cb) {
        $.ajax({
            type: "post",
            url: url,
            async: true,
            contentType: 'application/json',
            dataType: 'JSON',
            data: JSON.stringify(data),//将对象转为json字符串
            success: function (obj) {
                cb.success(obj);
            },
            error: function (obj) {
                cb.error(obj);
            }
        });
    },

    ajaxForm: function (form, url, cb) {
        let fields = $(form).serializeArray();
        let formData = {}; //声明一个对象
        $.each(fields, function (index, field) {
            formData[field.name] = field.value; //通过变量，将属性值，属性一起放到对象中
        })
        let data = JSON.stringify(formData);
        console.log("表单提交: " + form + " --> " + url);
        console.log(data);
        $.ajax({
            type: "post",
            url: url,
            async: true,
            contentType: 'application/json',
            dataType: 'JSON',
            data: data,//将对象转为json字符串
            success: function (obj) {
                cb.success(obj);
            },
            error: function (obj) {
                cb.error(obj);
            }
        });
    },
    ajaxDel: function (url, cb) {
        $.ajax({
            type: "delete",
            url: url,
            async: true,
            contentType: 'application/json',
            dataType: 'JSON',
            success: function (obj) {
                cb.success(obj);
            },
            error: function (obj) {
                cb.error(obj);
            }
        });
    }
};
